﻿<%@ Page Title="报表条件配置" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server">
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
	<link href="../assets/css/plugins/jsTree/style.min.css" rel="stylesheet" />
	<link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
	<link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
	<style>
		.system-box .right-side {
			width: 100%;
		}
		
		.system-box .right-content-box {
			overflow: hidden;
		}
		
		.mainContent {
			height: 100%;
			background-color: #ffffff;
			min-width: 650px;
		}
		
		.mainContent .part {
			height: 100%;
			display: inline-block;
			background-color: #ffffff;
			vertical-align: top;
			border: 1px solid #dddddd;
		}
		
		.mainContent .part .title {
			border-bottom: 1px solid #dddddd;
			height: 30px;
			line-height: 30px;
			padding-left: 5px;
			background-color: #eee;
		}
		
		.mainContent .part .title1 {
			border-bottom: 1px solid #dddddd;
			height: 42px;
			line-height: 42px;
			padding-left: 5px;
			background-color: #eee;
		}
		
		.leftPart {
			width: 350px;
			max-width: 500px;
			overflow: auto;
		}
		
		.rightPart {
			width: calc(100% - 355px);
			min-width: 320px;
			overflow: auto;
		}
		
		.leftPart .titleText {
			height: 30px;
			line-height: 30px;
			display: inline-block;
		}
		
		.rightPart .titleText {
			height: 30px;
			line-height: 30px;
			display: inline-block;
		}
		
		.leftPart .searchbox {
			width: 200px;
			display: inline-block;
			float: right;
		}
		
		.rightPart .searchbox {
			width: 180px;
			display: inline-block;
			float: right;
		}
		
		.btn-filter-users {
			-ms-border-radius: 0px;
			border-radius: 0px;
		}
		
		#prtList table {
			table-layout: fixed;
		}
		
		#prtList td {
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
		/*#reportDataList tr.check, .table-select tbody tr.check td:first-child {border-left: 4px solid #7acf89;}
        #reportDataList tr.check td, .table-select tbody tr.check td {background: #dff0d8;color: #222121;}*/
		
		.wxBox {
			position: absolute;
			right: 2px;
			top: 2px;
			display: inline-block;
		}
		
		.wxBox .dropdown-toggle {
			padding-top: 3px !important;
			padding-bottom: 3px !important;
		}
		
		.wxTitle {
			display: inline-block;
			position: relative;
			top: 1px;
		}
		
		.wxSelect {
			display: inline-block;
			min-width: 270px !important;
			top: 1px;
			float: right;
		}
		
		.sweet-alert h2 {
			line-height: 25px !important;
		}
		
		.cyl_table {
			margin-top: 3px;
			width: 100% !important;
		}
		
		.cyl_table1 {
			margin-bottom: 5px;
		}
		
		.cyl_tr {
			height: 30px !important;
		}
		
		.cyl_tr_td {
			background-color: #C0C0C0;
		}
		
		.copyitem {
			width: 60%;
			display: inline-block;
		}
		
		.set-from-group {
			margin: 0 auto 15px auto;
		}
	</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
	<div class="system-box">
		<div class="right-side">
			<div class="btns-container"></div>
			<%--新增弹出框begin--%>
			<div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content animated bounceInRight">
						<div class="modal-header">
							<span class="editTitle"></span>
							<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
						</div>
						<div id="message" style="display: none"></div>
						<div class="modal-body clearfix">
							<form class="form-horizontal">

								<div class="form-group set-from-group" id="WeChat">
									<div class="title1">
										<label for="ShopCode" class="col-sm-3 control-label">企业微信:</label>
										<div class="copyitem">
											<select id="wxWorkSelectListTop" class="selectpicker" title="选择消息类型" data-style="dropdownColor" data-width="100%">
											</select>
										</div>
									</div>
								</div>
								<div class="form-group set-from-group" id="TGReport">
									<label for="ShopCode" class="col-sm-3 control-label">目标报表:</label>
									<div class="copyitem">
										<select id="wxWorkSelectListBottom" class="selectpicker" title="选择消息类型" data-style="dropdownColor" data-width="100%">
										</select>
									</div>
								</div>
							</form>
							<br />
						</div>
						<div class="modal-footer">
							<button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
							<button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
						</div>
					</div>
				</div>
			</div>
			<%--新增弹出框end--%>

            <%--参数条件说明弹出框begin--%>
			<div class="modal inmodal" id="desWindow" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content animated bounceInRight">
						<div class="modal-header">
							<span class="desTitle"></span>
							<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
						</div>
						<%--<div id="message" style="display: none"></div>--%>
						<div class="modal-body clearfix" style="height:410px; overflow-x:scroll;">
							<p>一、字段解释</p>
                            <p>1、序号：排序,动态生成条件的顺序；</p>
                            <p>2、参数名：BI报表的参数名称；</p>
                            <p>3、文本描述：动态生成条件的文本描述；</p>
                            <p>4、控件类型：目前支持的表单控件类型有(时间、文本框、下拉框、复选框、单选框)；</p>
                            <p>5、控件ID：动态生成控件的ID,便于绑定事件；</p>
                            <p>6、数据源：主要针对下拉框控件要绑定的数据；单选框及复选框按“男;女;中性”等按格式输入的文本；</p>
                            <p>7、默认值：时间默认值按0,-1,1表示 当前天，前一天，后一天；下拉框指定文本为默认值(即绑定后的下拉值文本)；</p>
                            <p>8、级联关系：需要级联控件关联父控件的"控件ID"，建议最多三级联动；</p>
                            <p>二、数据源</p>
                            <p>1、数据源字段的配置目前只对控件类型为 下拉框、复选框、单选框 控件起作用</p>
                            <p>2、配置下拉框控件需要在数据源字段选中一个获取数据的PAI对象</p>
                            <p>3、配置复选框控件需要在数据源字段输入复选的参数如：东;南;西;北 中间按英文分号隔开</p>
                            <p>4、配置单选框控件需要在数据源字段输入复选的参数如：东;南;西;北 中间按英文分号隔开</p>
                            <p>三、复制功能</p>
                            <p>1、在左侧报表列表中选中一个相同参数的报表，点击复制按钮，在弹出框中选择你需要把参数复制到的目标报表点击保存即可。</p>
							<br />
						</div>
					</div>
				</div>
			</div>
			<%--参数条件说明弹出框end--%>

			<div class="right-content-box">
				<div class="mainContent">
					<div class="wxBox">
					</div>
					<div class="leftPart part">
						<div class="title1">
							<div class="wxTitle">企业微信：</div>
							<div class="wxSelect">
								<select id="wxWorkSelectList" class="selectpicker" title="选择消息类型" data-style="dropdownColor" data-width="100%">
								</select>
							</div>
						</div>
						<div class="title">
							<div class="titleText">
								报表列表
							</div>
							<div class="searchbox">
								<div class="input-group">
									<input type="text" class="form-control input-sm filter-users" id="searchUser" placeholder="报表名称">
									<span class="input-group-btn">
                                        <button class="btn btn-primary btn-filter-users btn-sm" type="button">查找</button>
                                    </span>
								</div>
							</div>
						</div>
						<div id="">
							<table class="footable table table-stripped table-list">
								<thead>
									<tr>
										<th style="width: 40px;">选中</th>
										<th>报表名称</th>
									</tr>
								</thead>
								<tbody id="ReportList"></tbody>
							</table>
						</div>
					</div>
					<div class="rightPart part">
						<div class="title">
							<div class="titleText">
								报表条件列表
                                <a id="aDescribe" class="right-sidebar-toggle" aria-expanded="false">
                                    <i class="fa fa-tasks"></i>说明
                                </a>
							</div>
						</div>
						<div id="prtList">
							<table id="addTable0" class="cyl_table cyl_table1" border="1" cellpadding="0" cellspacing="0" style="border:none;">
								<tr class="cyl_tr">
									<td class="cyl_tr_td" style="width:4%; text-align:center">序号</td>
									<td class="cyl_tr_td" style="width:16%; text-align:center">参数名</td>
									<td class="cyl_tr_td" style="width:14%; text-align:center">文本描述</td>
									<td class="cyl_tr_td" style="width:12%; text-align:center">控件类型</td>
									<td class="cyl_tr_td" style="width:12%; text-align:center">控件ID</td>
									<td class="cyl_tr_td" style="width:16%; text-align:center">数据源</td>
									<td class="cyl_tr_td" style="width:10%; text-align:center">默认值</td>
									<td class="cyl_tr_td" style="width:12%; text-align:center">级联关系</td>
									<td style="border:none; width:4%;"></td>
								</tr>
								<%--<tr class="cyl_tr">
                                    <td><input id="txtConfig_sequence" type="text" style="width:100%; height:30px; text-align:center;" maxlength="2" /></td>
                                    <td><input id="txtConfig_paramname" type="text" style="width:100%; height:30px; text-align:center;" maxlength="50" /></td>
                                    <td><input id="txtConfig_textdescription" type="text" style="width:100%; height:30px; text-align:center;" maxlength="5" /></td>
                                    <td>
                                        <select id="selConfig_controltype" style="width:100%; height:30px;" onchange="BindConfigSource('0',1);">
                                            <option value="时间">时间</option>
                                            <option value="文本框">文本框</option>
                                            <option value="下拉框">下拉框</option>
                                            <option value="复选框">复选框</option>
                                            <option value="单选框">单选框</option>
                                        </select>
                                    </td>
                                    <td><input id="txtConfig_controlid" type="text" style="width:100%; height:30px; text-align:center;" maxlength="20" /></td>
                                    <td>
                                        <input id="txtConfig_source" type="text" style="width:100%; height:30px; text-align:center;" maxlength="25" />
                                        <select id="selConfig_source" style="width:100%; height:30px;">
                                            <option value="">默认为空</option>
                                        </select>
                                    </td>
                                    <td><input id="txtConfig_value" type="text" style="width:100%; height:30px; text-align:center;" maxlength="25" /></td>
                                    <td><input id="txtConfig_cascade" type="text" style="width:100%; height:30px; text-align:center;" maxlength="20" /></td>
                                    <td style="border:none;">
                                        <img id="imgAddDel01" alt="0" src="../assets/img/u14515.png" style="cursor: pointer;" onclick="AddRemove_Row('0',1);" />
                                    </td>
                                </tr>--%>
								<tr class="cyl_tr">
									<td style="text-align:center">+</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td style="border:none;">
										<img alt="添加" src="../assets/img/u14516.png" style="cursor: pointer;" onclick="AddAdd_Row('0');" />
									</td>
								</tr>
							</table>

						</div>
					</div>

				</div>
			</div>
		</div>
	</div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
	<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
	<script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
	<script src="../assets/js/page/rScroll.js"></script>
	<script src="../assets/js/page/pageControl.js"></script>
	<%--<script src="../assets/js/page/tableControl.js"></script>--%>
	<script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
	<script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>

	<script type="text/html" id="tpl-msg-item">
		{{# for(var i = 0, len = d.length; i
		< len; i++){ }} <tr {{# if(i%2==0 ){ }} class="gradeX footable-even" {{# }else{ }} class="gradeX footable-odd" {{# } }}>
			<td class="Id" style="display: none;">{{d[i].Id}}</td>
			<td><input type="radio" name="msg" class="checkPlan" data-index="{{i}}" /></td>
			<td class="Title" title="{{d[i].Title}}">{{d[i].Title}}</td>
			</tr>
			{{# } }}
	</script>
	<script>
		//数据源接口名称数组
		var ApiConfig_source = [];
		var ParameterList = [];
		var ReportID = 0;
		$(document).ready(function() {
			//模块ID
			var ModuleID = Y.getUrlParam("ModuleID");

			//获取按钮
			commonUtil.loadBtnList(ModuleID, function() {
				rScroll();
				$('#copyBtn').attr("disabled", "disabled")
			});

			//绑定下拉框
			var bindWxCorpInfoList = function(controller, action, params, els, size, setDefault, callback) {
				Y.API2(controller, action, params, function(data) {
					if(data.Success == false) {
						swal(data.Message, '', 'error');
					} else {
						var html = '';
						if(setDefault) {
							html = '<option value="">请选择</option>';
						}
						data.map(function(item) {
							html += '<option value=' + item.CIdentification + '>' + item.CorpName + '</option>';
						});
						els.map(function(item) {
							$(item).html("");
							$(item).html(html);
							$(item).selectpicker({
								size: size,
								'title': '请选择'
							});
							$(item).selectpicker('refresh');
						});
						if(typeof callback === "function") {
							callback();
						}
					}
				});
			}
			//绑定报表下拉框
			var bindGetReportList = function(controller, action, params, els, size, setDefault, callback) {
				console.log('wxWorkTopId')
				Y.API2(controller, action, params, function(data) {
					if(data.Success == false) {
						swal(data.Message, '', 'error');
					} else {
						var html = '';
						if(setDefault) {
							html = '<option value="">请选择</option>';
						}
						data.map(function(item) {
							html += '<option value=' + item.Id + '>' + item.Title + '</option>';
						});
						els.map(function(item) {
							$(item).html("");
							$(item).html(html);
							$(item).selectpicker({
								size: size,
								'title': '请选择'
							});
							$(item).selectpicker('refresh');
						});
						if(typeof callback === "function") {
							callback();
						}
					}
				});
			}
			//绑定数据到企业微信下拉框wxWorkSelectListTop
			var loadWxCorpInfoList = function(els, callback) {
				bindWxCorpInfoList('WxCorpInfo', 'GetWxCorpInfoList', {}, els, 8, true, callback);
			}
			//绑定数据到报表下拉框
			var loadGetReportList = function(els, parma, callback) { //CIdentification
				bindGetReportList('WxConditionConfig', 'GetReportList', parma, els, 8, true, callback);
			}

			//获取数据源接口名称
			var loadGetApiName = function() {
				Y.API2('WxDataSource', 'GetApiName', {}, function(data) {
					if(data.Success == false) {
						ApiConfig_source = [];
					} else {
						ApiConfig_source = data;
						//console.log(ApiConfig_source);
					}
				});
			}

			//如果有错误就弹出来并返回
			var errorIfNull = function(val, msg) {
				var tmp = val || "";
				if(tmp === "") {
					swal(msg, '', 'error');
					return true;
				}
				return false;
			}

			//获取列表
			var loadReportList = function() {
				//获取顶部的过滤条件
				var conditionTitle = $('.leftPart .filter-users').val().trim().replace(/'/g, '');
				var wxWorkId = $('#wxWorkSelectList').selectpicker('val');
				pageControl.init('WxConditionConfig', 'GetReportList', {
					conditionTitle: conditionTitle,
					needLayer: true,
					CIdentification: wxWorkId,
					alwaysCallBack: function() {
						$('#ReportList').empty();
					}
				}, function(result) {
					if(result.data.length > 0) {
						var tBody = [];
						if(!Y.checkNull(result)) {
							if(result.data.length == 0) {
								Y.NoData(body, 5);
								return false;
							}
							var pl = document.getElementById('tpl-msg-item').innerHTML;

							laytpl(pl).render(result.data, function(html) {
								document.getElementById('ReportList').innerHTML = html;

								$(".checkPlan").iCheck({
									checkboxClass: "icheckbox_square-green",
									radioClass: "iradio_square-green"
								});

								$('.checkPlan').on('ifChecked', function(event) {
									$('.footable tr').removeClass('check');
									$(this).parents('tr').addClass('check');
									//处理点击事件没有请求api
									$('#copyBtn').removeAttr("disabled")
									ReportID = $(this).parents('tr').find('.Id').text();
									Y.API2('WxConditionConfig', 'GetWxReportConfig', {
										"reportId": ReportID
									}, function(data) {
										AddRemove_AllRow('0');
										if(data.Success == false) {
											ParameterList = [];
										} else {
											ParameterList = data;
											//console.log(ParameterList);
											BindAddData('0');
										}
									});
								});

							});
							rScroll();
						}
					}
				});
			}

			//选中记录
			$('#ReportList').on('click', 'tr', function() {
				var parentTr = $('#ReportList tr');
				if($(this).hasClass('check')) {
					$(parentTr).removeClass('check');
					$(parentTr).find('.checkPlan').iCheck('uncheck');
				} else {
					$(parentTr).removeClass('check');
					$(this).addClass('check');

					$(parentTr).find('.checkPlan').iCheck('uncheck');
					$(this).find('.checkPlan').iCheck('check');

					var id = $(this).find('.Id').text(); //这里是选中id
					ReportID = id;
					Y.API2('WxConditionConfig', 'GetWxReportConfig', {
						"reportId": id
					}, function(data) {
						AddRemove_AllRow('0');
						if(data.Success == false) {
							ParameterList = [];
						} else {
							ParameterList = data;
							//console.log(ParameterList);
							BindAddData('0');
						}
					});
				}
			});

			//提交
			$(document).on("click", "#btn-save", function() {
				GetAddData('0', '0');
				if(ParameterList.length > 0) {
					var rowNum = IsCascadeId();
					if(IsScoreZero == true) {
						swal('序号、参数名、文本描述、控件ID 不能为空', '', 'error');
					} else if(rowNum != 0) {
						var CascadeId = document.getElementById("txtConfig_cascade" + "0" + rowNum).value;
						swal('级联关系ID：' + CascadeId + ' 不存在', '', 'error');
					} else {
						var param = {
							"report_id": ReportID,
							"list": ParameterList
						};
						//console.log(param);
						Y.API2('WxConditionConfig', 'SaveReportList', param, function(data) {
							if(data.Success == false) {
								swal(data.Message, '', 'error');
							} else {
								swal('保存成功', '', 'success');
							}
						});
					}
				}

			});
			//设置复制按钮显示
			$(document).on('click', '#ReportList', function() {
				$('#copyBtn').removeAttr("disabled")
			})
			//复制

			$(document).on('click', '#copyBtn', function() {
				if(Y.checkNull(ParameterList)) {
					swal('当前复制的报表内容不能为空', '', 'warning');
					return
				}
				$('#addWindow').css('display', 'block')
				$('.editTitle').text('新增数据');
				loadWxCorpInfoList(["#wxWorkSelectListTop"]);
            });

            //报表条件配置-功能说明
            $(document).on('click', '#aDescribe', function () {
                $('#desWindow').css('display', 'block')
                $('.desTitle').text('报表条件配置-功能说明');
            });

			var selectClose = function(dom) {
				$(document).on('click', dom, function() {
                    $('#addWindow').css('display', 'none')
                    $('#desWindow').css('display', 'none')
				});
			}

			//copyEnd

			selectClose('#closeAddBox');
			selectClose('.close');

			$(".leftPart .btn-filter-users").on("click", function() {
				loadReportList();
			});

			$('#wxWorkSelectList').on('changed.bs.select', function(e) {
				var wxWorkId = $('#wxWorkSelectList').selectpicker('val');
				loadReportList();
				$('#copyBtn').attr("disabled", "disabled")
			});

			//copychange
			$('#wxWorkSelectListTop').on('changed.bs.select', function(e) {
				var wxWorkTopId = $('#wxWorkSelectListTop').selectpicker('val');
				loadGetReportList(["#wxWorkSelectListBottom"], {
					CIdentification: wxWorkTopId
				})
			});
			//copysave
			$(document).on('click', '#addModuleBtn', function() {

				if(Y.checkNull($('#ReportList .check .Id').text())) {
					swal('请选择报表名称', '', 'warning');
					return
				}
				if(Y.checkNull($('#wxWorkSelectListBottom').selectpicker('val'))) {
					swal('请选择目标报表', '', 'warning');
					return
				}
				if($('#ReportList .check .Id').text() == $('#wxWorkSelectListBottom').selectpicker('val')) {
					swal('请不要选择相同目标报表', '', 'warning');
					return
				}
				var parmaVal = {
					SourceID: $('#ReportList .check .Id').text(),
					TargetID: $('#wxWorkSelectListBottom').selectpicker('val')
				}

				Y.API2('WxConditionConfig', 'CopyReport', parmaVal, function(data) {
					if(false == data.Success) {
						swal(data.Message, '', 'error');
						return
					}
					swal('复制成功', '', 'success');
					loadWxCorpInfoList(["#wxWorkSelectListTop"]);
					$('#wxWorkSelectListBottom').html('<option value="">请选择</option>');
					$('#wxWorkSelectListBottom').selectpicker({
						size: 8,
						'title': '请选择'
					});
					$('#wxWorkSelectListBottom').selectpicker('refresh');
					$('#addWindow').css('display', 'none')

				})
			})

			//默认加载消息模板
			loadWxCorpInfoList(["#wxWorkSelectList"]);

			loadReportList();
			loadGetApiName();

		})

		//创建时重新画表格
		function BindAddData(pIndex) {
			var objTable = document.getElementById("addTable" + pIndex);
			for(var index = 1; index < ParameterList.length + 1; index++) {
				var nextRow = objTable.insertRow(index);

				var str_td = "<td><input id=\"txtConfig_sequence" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"2\" onkeyup=\"IsNum(this,'" + pIndex + "'," + index + ");\" /></td>";
				str_td = str_td + "<td><input id=\"txtConfig_paramname" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"50\" /></td>";
				str_td = str_td + "<td><input id=\"txtConfig_textdescription" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"5\" /></td>";
				str_td = str_td + "<td><select id=\"selConfig_controltype" + pIndex + index + "\" style=\"width:100%; height:30px;\" onchange=\"BindConfigSource('" + pIndex + "', " + index + ");\" >";
				str_td = str_td + "<option value=\"time\">时间</option>";
				str_td = str_td + "<option value=\"text\">文本框</option>";
				str_td = str_td + "<option value=\"dropdown\">下拉框</option>";
				str_td = str_td + "<option value=\"checkbox\">复选框</option>";
				str_td = str_td + "<option value=\"radio\">单选框</option>";
				str_td = str_td + "</select></td>";
				str_td = str_td + "<td><input id=\"txtConfig_controlid" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"20\" onblur=\"IsBlur(this,'" + pIndex + "'," + index + ");\" /></td>";

				var htmlConfig_source = "<option value=\"\">默认为空</option>";
				for(var i = 0; i < ApiConfig_source.length; i++) {
					htmlConfig_source += "<option value=\"" + ApiConfig_source[i].Api + "\">" + ApiConfig_source[i].ApiName + "</option>";
				}
				str_td = str_td + "<td><input id=\"txtConfig_source" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"25\" placeholder=\"\" />";
				str_td = str_td + "<select id=\"selConfig_source" + pIndex + index + "\" style=\"width:100%; height:30px;\" >" + htmlConfig_source + "</select></td>";

				str_td = str_td + "<td><input id=\"txtConfig_value" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"25\" /></td>";
				str_td = str_td + "<td><input id=\"txtConfig_cascade" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"20\" onblur=\"IsBlurId(this,'" + pIndex + "'," + index + ");\" /></td>";
				str_td = str_td + "<td style=\"border:none;\"><img id=\"imgAddDel" + pIndex + index + "\" alt=\"0\" src=\"../assets/img/u14515.png\" style=\"cursor: pointer;\" onclick=\"AddRemove_Row('" + pIndex + "'," + index + ");\" /></td>";

				nextRow.innerHTML = str_td;
				nextRow.className = "cyl_tr";

				document.getElementById("txtConfig_sequence" + pIndex + index).value = ParameterList[index - 1].config_sequence;
				document.getElementById("txtConfig_paramname" + pIndex + index).value = ParameterList[index - 1].config_paramname;
				document.getElementById("txtConfig_textdescription" + pIndex + index).value = ParameterList[index - 1].config_textdescription;
				$("#selConfig_controltype" + pIndex + index).val(ParameterList[index - 1].config_controltype);
				document.getElementById("txtConfig_controlid" + pIndex + index).value = ParameterList[index - 1].config_controlid;

				document.getElementById("txtConfig_value" + pIndex + index).value = ParameterList[index - 1].config_value;
				document.getElementById("txtConfig_cascade" + pIndex + index).value = ParameterList[index - 1].config_cascade;
				document.getElementById("imgAddDel" + pIndex + index).alt = ParameterList[index - 1].config_id;

				if(ParameterList[index - 1].config_controltype == "dropdown") {
					$("#selConfig_source" + pIndex + index).val(ParameterList[index - 1].config_source);
					$("#txtConfig_source" + pIndex + index).hide();
					$("#selConfig_source" + pIndex + index).show();

				} else {
					$("#txtConfig_source" + pIndex + index).val(ParameterList[index - 1].config_source);
					$("#txtConfig_source" + pIndex + index).show();
					$("#selConfig_source" + pIndex + index).hide();
					var txtType = ParameterList[index - 1].config_controltype;
					if(txtType == "checkbox" || txtType == "radio") {
						document.getElementById("txtConfig_source" + pIndex + index).placeholder = "多值以 ; 隔开";
					} else {
						document.getElementById("txtConfig_source" + pIndex + index).placeholder = "";
					}
				}
			}
		}

		//创建父巡检中的子类
		function AddAdd_Row(pIndex) {
			var objTable = document.getElementById("addTable" + pIndex);
			var index = objTable.rows.length - 1;
			var nextRow = objTable.insertRow(index);
			//alert(index);

			var str_td = "<td><input id=\"txtConfig_sequence" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"2\" onkeyup=\"IsNum(this,'" + pIndex + "'," + index + ");\" /></td>";
			str_td = str_td + "<td><input id=\"txtConfig_paramname" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"50\" /></td>";
			str_td = str_td + "<td><input id=\"txtConfig_textdescription" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"5\" /></td>";
			str_td = str_td + "<td><select id=\"selConfig_controltype" + pIndex + index + "\" style=\"width:100%; height:30px;\" onchange=\"BindConfigSource('" + pIndex + "', " + index + ");\" >";
			str_td = str_td + "<option value=\"time\">时间</option>";
			str_td = str_td + "<option value=\"text\">文本框</option>";
			str_td = str_td + "<option value=\"dropdown\">下拉框</option>";
			str_td = str_td + "<option value=\"checkbox\">复选框</option>";
			str_td = str_td + "<option value=\"radio\">单选框</option>";
			str_td = str_td + "</select></td>";
			str_td = str_td + "<td><input id=\"txtConfig_controlid" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"20\" onblur=\"IsBlur(this,'" + pIndex + "'," + index + ");\" /></td>";

			var htmlConfig_source = "<option value=\"\">默认为空</option>";
			for(var i = 0; i < ApiConfig_source.length; i++) {
				htmlConfig_source += "<option value=\"" + ApiConfig_source[i].Api + "\">" + ApiConfig_source[i].ApiName + "</option>";
			}
			str_td = str_td + "<td><input id=\"txtConfig_source" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"25\" placeholder=\"\" />";
			str_td = str_td + "<select id=\"selConfig_source" + pIndex + index + "\" style=\"width:100%; height:30px;\" >" + htmlConfig_source + "</select></td>";

			str_td = str_td + "<td><input id=\"txtConfig_value" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"25\" /></td>";
			str_td = str_td + "<td><input id=\"txtConfig_cascade" + pIndex + index + "\" type=\"text\" style=\"width:100%; height:30px; text-align:center;\" maxlength=\"20\" onblur=\"IsBlurId(this,'" + pIndex + "'," + index + ");\" /></td>";
			str_td = str_td + "<td style=\"border:none;\"><img id=\"imgAddDel" + pIndex + index + "\" alt=\"0\" src=\"../assets/img/u14515.png\" style=\"cursor: pointer;\" onclick=\"AddRemove_Row('" + pIndex + "'," + index + ");\" /></td>";

			nextRow.innerHTML = str_td;
			nextRow.className = "cyl_tr";

		}

		//切换数据源绑定控件
		function BindConfigSource(pIndex, index) {
			if($("#selConfig_controltype" + pIndex + index).val() == "dropdown") {
				$("#txtConfig_source" + pIndex + index).hide();
				$("#selConfig_source" + pIndex + index).show();
			} else {
				$("#txtConfig_source" + pIndex + index).show();
				$("#selConfig_source" + pIndex + index).hide();
				var txtType = $("#selConfig_controltype" + pIndex + index).val();
				if(txtType == "checkbox" || txtType == "radio") {
					document.getElementById("txtConfig_source" + pIndex + index).placeholder = "多值以 ; 隔开";
				} else {
					document.getElementById("txtConfig_source" + pIndex + index).placeholder = "";
				}
			}
		}

		//验证序号只能输入数值
		function IsNum(obj, pIndex, index) {
			obj.value = obj.value.replace(/[^\d]/g, "");
			if(obj.value == "") {
				obj.value = 1;
			}
			//过滤只能1-10
			if(obj.value <= 0) {
				obj.value = 1;
			}
		}

		//判断控件ID的唯一
		function IsBlur(obj, pIndex, index) {
			if(obj.value != "") {
				GetAddData(pIndex, index);
				var isBol = 0;
				for(var i = 0; i < ParameterList.length; i++) {
					if(obj.value == ParameterList[i].config_controlid) {
						obj.value = "";
						isBol = 1;
						break;
					}
				}
				if(isBol == 1) {
					swal("控件ID重复了", '', 'error');
				}
			}
		}

		//移除表格里的所有行
		function AddRemove_AllRow(pIndex) {
			var objTable = document.getElementById("addTable" + pIndex);
			var length = objTable.rows.length - 1;
			for(var j = 1; j < length; j++) {
				var countRow = objTable.rows.length;
				if(countRow > 2) {
					objTable.deleteRow(1);
				}
			}
		}

		//前端移除单条数据
		function AddRemove_Row(pIndex, index) {
			var objTable = document.getElementById("addTable" + pIndex);
			var length = objTable.rows.length - 1;
			GetAddData(pIndex, index);
			var txtConfig_controlid = document.getElementById("txtConfig_controlid" + pIndex + index).value;
			if(IsRemove_RowId(txtConfig_controlid) == 0) {
				for(var j = 1; j < length; j++) {
					var countRow = objTable.rows.length;
					if(countRow > 2) {
						objTable.deleteRow(1);
					}
				}
				BindAddData(pIndex);
			} else {
				swal("父控件ID被级联引用请先取消级联关系", '', 'error');
			}
		}

		//移除前检查是否存在级联关系
		function IsRemove_RowId(controlId) {
			var isBol = 0;
			var txtConfig_controlid = controlId;
			if(txtConfig_controlid != "") {
				for(var i = 0; i < ParameterList.length; i++) {
					if(txtConfig_controlid == ParameterList[i].config_cascade) {
						isBol = 1;
					}
				}
			}
			return isBol;
		}

		//判断级联控件ID是否存在
		function IsBlurId(obj, pIndex, index) {
			if(obj.value != "") {
				GetAddData(pIndex, index);
				var isBol = 0;
				for(var i = 0; i < ParameterList.length; i++) {
					if(obj.value == ParameterList[i].config_controlid) {
						isBol = 1;
						break;
					}
				}
				if(isBol == 0) {
					obj.value = "";
					swal("级联父控件ID不存在", '', 'error');
				}
			}
		}

		//保存前判断联控件ID是否存在都存在
		function IsCascadeId() {
			var rowNum = 0;
			for(var i = 0; i < ParameterList.length; i++) {
				if(ParameterList[i].config_cascade != "") {
					var isBol = 0;
					for(var j = 0; j < ParameterList.length; j++) {
						if(ParameterList[i].config_cascade == ParameterList[j].config_controlid) {
							isBol = 1;
							break;
						}
					}
					if(isBol == 0) {
						rowNum = i + 1;
						break;
					}
				}
			}
			return rowNum;
		}

		//标记子项名称是否为空或占比是否有为零
		var IsScoreZero = false;
		//获取创建时的表格数据
		function GetAddData(pIndex, index) {
			var objTable = document.getElementById("addTable" + pIndex);
			var length = objTable.rows.length - 1;
			ParameterList = [];
			IsScoreZero = false;
			for(var i = 1; i < length; i++) {
				if(i != index) {
					var txtConfig_sequence = document.getElementById("txtConfig_sequence" + pIndex + i).value;
					var txtConfig_paramname = document.getElementById("txtConfig_paramname" + pIndex + i).value;
					var txtConfig_textdescription = document.getElementById("txtConfig_textdescription" + pIndex + i).value;
					var selConfig_controltype = document.getElementById("selConfig_controltype" + pIndex + i).value;
					var txtConfig_controlid = document.getElementById("txtConfig_controlid" + pIndex + i).value;

					var selConfig_source = "";
					if(selConfig_controltype == "dropdown") {
						selConfig_source = document.getElementById("selConfig_source" + pIndex + i).value;
					} else {
						selConfig_source = document.getElementById("txtConfig_source" + pIndex + i).value;
					}

					var txtConfig_value = document.getElementById("txtConfig_value" + pIndex + i).value;
					var txtConfig_cascade = document.getElementById("txtConfig_cascade" + pIndex + i).value;
					var txtConfig_id = document.getElementById("imgAddDel" + pIndex + i).alt;

					if(txtConfig_sequence == "" || txtConfig_textdescription == "" || txtConfig_controlid == "" || txtConfig_paramname == "") {
						IsScoreZero = true;
					}

					var item = {
						"report_id": ReportID,
						"config_sequence": txtConfig_sequence,
						"config_textdescription": txtConfig_textdescription,
						"config_controltype": selConfig_controltype,
						"config_controlid": txtConfig_controlid,
						"config_source": selConfig_source,
						"config_value": txtConfig_value,
						"config_cascade": txtConfig_cascade,
						"config_paramname": txtConfig_paramname
					};
					ParameterList.push(item);
				}
			}
			console.log(ParameterList);
		}
	</script>
</asp:Content>